//
//  DemoController.swift
//  Practice
//
//  Created by miaozhihui on 2017/1/10.
//  Copyright © 2017年 DeKuTree. All rights reserved.
//

import UIKit

private let cellId = "cellId"

class DemoController: BaseController {
    
    override func viewDidLoad() {
        super.viewDidLoad()
        title = "第\(navigationController?.childViewControllers.count ?? 0)个"
    }
    
    /// 微博数据数组
    fileprivate lazy var statusList = [String]()
    
    /// 加载数据
    override func loadData() {
        for i in 0..<15 {
            // 将数据插入到数组的顶部
            statusList.insert(i.description, at: 0)
        }
    }
    
    @objc fileprivate func showNext() {
        
        let vc = DemoController()
        
        navigationController?.pushViewController(vc, animated: true)
        
    }
}

// MARK: -表格数据源方法
extension DemoController {
    override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        return statusList.count
    }
    override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        let cell = tableView.dequeueReusableCell(withIdentifier: cellId, for: indexPath)
        cell.textLabel?.text = statusList[indexPath.row]
        return cell
    }
}

extension DemoController {
    
    /// 重写父类方法
    override func setupTableView() {
        super.setupTableView()
        // 设置导航栏按钮
        navItem.rightBarButtonItem = UIBarButtonItem(title: "下一个", target: self, action: #selector(showNext))
        
        // 注册原型 cell
        tableView?.register(UITableViewCell.self, forCellReuseIdentifier: cellId)
    }
}
